#!/usr/bin/env python
# coding=utf-8
#from django.db import models
from google.appengine.ext import db
from django import newforms as forms

# Create your models here.

class UserData(db.Model):
    user = db.UserProperty(required=True)
    userEmail = db.EmailProperty()
    updatedDatetime = db.DateTimeProperty(auto_now=True)

class Account(db.Model):
    user = db.UserProperty(required=True)
    name = db.StringProperty(required=True)
    initialValue = db.FloatProperty(required=True, default=0.0)
    accountType = db.IntegerProperty(required=True)
    note= db.TextProperty()
    createdDatetime = db.DateTimeProperty(auto_now_add=True)
        	
    def __str__(self):
    	return '%s' %self.name
   	

class Category(db.Model):
    user = db.UserProperty(required=True)
    name = db.StringProperty(required=True)
    order = db.IntegerProperty(default=0)
    note= db.TextProperty()
    createdDatetime = db.DateTimeProperty(auto_now_add=True)

    def __str__(self):
    	return '%s' %self.name    
    
class Record(db.Model):
    account = db.ReferenceProperty(required=True, reference_class=Account)
    action = db.IntegerProperty(required=True)
    value = db.FloatProperty(default=0, required=True)
    recordDate = db.DateProperty(required=True)
    reason = db.StringProperty(required=True)
    category = db.ReferenceProperty(reference_class=Category, default=None)
    note= db.TextProperty()
    createdDatetime = db.DateTimeProperty(auto_now_add=True)

class Transaction(db.Model):
    user = db.UserProperty(required=True)
    sourceRecord = db.ReferenceProperty(collection_name="source_record_set", reference_class=Record, required=True)
    sourceAccount = db.ReferenceProperty(collection_name="source_account_set", reference_class=Account, required=True)
    destinationRecord = db.ReferenceProperty(collection_name="destination_record_set", reference_class=Record, required=True)
    destinationAccount = db.ReferenceProperty(collection_name="destination_account_set", reference_class=Account, required=True)
